From 19c5a00f3a3c1959b2f7e3aec896399e7372440a Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sun, 4 Aug 2013 11:40:43 +0200 Subject: [PATCH] iconfactory: cache/invalidate pixbufs according to the effect The state of the widget is not enough now to cache the pixbuf - we also have to take into consideration the image effect itself, since the state on the actual GtkStyleContext we use might not change, e.g. because the change was on a parent context. https://bugzilla.gnome.org/show_bug.cgi?id=705443 --- gtk/deprecated/gtkiconfactory.c | 45 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/gtk/deprecated/gtkiconfactory.c b/gtk/deprecated/gtkiconfactory.c index a3427ae5b4..01a4e5f29d 100644 --- a/gtk/deprecated/gtkiconfactory.c +++ b/gtk/deprecated/gtkiconfactory.c @@ -30,6 +30,7 @@ #include #include +#include "gtkcssenumvalueprivate.h" #include "gtkiconfactory.h" #include "gtkiconcache.h" #include "gtkdebug.h" @@ -42,6 +43,7 @@ #include "gtkbuilderprivate.h" #include "gtktypebuiltins.h" #include "gtkstyle.h" +#include "gtkstylecontextprivate.h" /** * SECTION:gtkiconfactory @@ -993,13 +995,15 @@ static GdkPixbuf *find_in_cache (GtkIconSet *icon_set, GtkTextDirection direction, GtkStateType state, GtkIconSize size, - gint scale); + gint scale, + GtkCssImageEffect effect); static void add_to_cache (GtkIconSet *icon_set, GtkStyleContext *style_context, GtkTextDirection direction, GtkStateType state, GtkIconSize size, gint scale, + GtkCssImageEffect effect, GdkPixbuf *pixbuf); /* Clear icon set contents, drop references to all contained * GdkPixbuf objects and forget all GtkIconSources. Used to @@ -1512,6 +1516,7 @@ gtk_icon_set_render_icon_pixbuf_for_scale (GtkIconSet *icon_set, GtkStateFlags flags = 0; GtkStateType state; GtkTextDirection direction; + GtkCssImageEffect effect; g_return_val_if_fail (icon_set != NULL, NULL); g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL); @@ -1528,9 +1533,12 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS; direction = gtk_style_context_get_direction (context); G_GNUC_END_IGNORE_DEPRECATIONS; + effect = _gtk_css_image_effect_value_get + (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_GTK_IMAGE_EFFECT)); + if (icon_set->sources) { - icon = find_in_cache (icon_set, context, direction, state, size, scale); + icon = find_in_cache (icon_set, context, direction, state, size, scale, effect); if (icon) return g_object_ref (icon); } @@ -1542,7 +1550,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS; if (icon == NULL) icon = render_fallback_image (context, direction, state, size); - add_to_cache (icon_set, context, direction, state, size, scale, icon); + add_to_cache (icon_set, context, direction, state, size, scale, effect, icon); return icon; } @@ -2466,6 +2474,7 @@ struct _CachedIcon GtkStateType state; GtkIconSize size; gint scale; + GtkCssImageEffect effect; GdkPixbuf *pixbuf; }; @@ -2490,12 +2499,13 @@ cached_icon_free (CachedIcon *icon) } static GdkPixbuf * -find_in_cache (GtkIconSet *icon_set, - GtkStyleContext *style_context, - GtkTextDirection direction, - GtkStateType state, - GtkIconSize size, - gint scale) +find_in_cache (GtkIconSet *icon_set, + GtkStyleContext *style_context, + GtkTextDirection direction, + GtkStateType state, + GtkIconSize size, + gint scale, + GtkCssImageEffect effect) { GSList *tmp_list; GSList *prev; @@ -2511,6 +2521,7 @@ find_in_cache (GtkIconSet *icon_set, if (icon->style == style_context && icon->direction == direction && icon->state == state && + icon->effect == effect && (size == (GtkIconSize)-1 || icon->size == size)) { if (prev) @@ -2532,13 +2543,14 @@ find_in_cache (GtkIconSet *icon_set, } static void -add_to_cache (GtkIconSet *icon_set, - GtkStyleContext *style_context, - GtkTextDirection direction, - GtkStateType state, - GtkIconSize size, - gint scale, - GdkPixbuf *pixbuf) +add_to_cache (GtkIconSet *icon_set, + GtkStyleContext *style_context, + GtkTextDirection direction, + GtkStateType state, + GtkIconSize size, + gint scale, + GtkCssImageEffect effect, + GdkPixbuf *pixbuf) { CachedIcon *icon; @@ -2555,6 +2567,7 @@ add_to_cache (GtkIconSet *icon_set, icon->state = state; icon->size = size; icon->scale = scale; + icon->effect = effect; icon->pixbuf = pixbuf; attach_to_style (icon_set, icon->style); -- 2.30.2